package com.shd.edanpei.customer.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.shd.edanpei.R;
import com.shd.edanpei.base.BaseActivity;
import com.shd.edanpei.base.BaseIPresenter;
import com.shd.edanpei.common.Constant;
import com.shd.edanpei.bean.DataBean;
import com.shd.edanpei.customer.adapter.ListAdapter;

import java.lang.reflect.Type;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by mc on 2018/9/28.
 * yang-wen-wen
 */

public class ListActivity extends BaseActivity {

    @BindView(R.id.headline)
    TextView headline;
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;

    ListAdapter mAdapter;

    @Override
    protected int setLayout() {
        return R.layout.activity_list;
    }

    @Override
    protected BaseIPresenter bindPresenter() {
        return null;
    }

    @Override
    protected void initView(@Nullable Bundle savedInstanceState) {
        Bundle extras = getIntent().getExtras();
        headline.setText(extras.getString(Constant.TITLE));
        Type type = new TypeToken<List<DataBean>>() {
        }.getType();
        List<DataBean> list = new Gson().fromJson(extras.getString(Constant.DATA), type);

        mAdapter = new ListAdapter(this);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(mAdapter);
        mAdapter.setNewData(list);
    }

    @Override
    protected void initListener() {

    }

    @OnClick(R.id.iv_headline_back)
    void onClose() {
        finish();
    }
}
